package cn.antblog.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * 时间戳的加减
 * @author YangJingyi
 * @date 2021-05-20 10:49
 */
public class timestDiff {


    public static void main(String[] args) throws ParseException {
        Date date = new Date();
//        SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
//        String format = df.format(new Date(date.getTime() - 2 * 24 * 60 * 60 * 1000));
//        System.out.println("两天前的日期：" + df.format(new Date(date.getTime() - 2 * 24 * 60 * 60 * 1000)));
        long l = System.currentTimeMillis();
        String timest =  "2021052501245";
        String substring = timest.substring(0,8);
        SimpleDateFormat sdf =  new SimpleDateFormat("yyyyMMdd");
        Date parse = sdf.parse(substring);
        long time1 = parse.getTime();
        Date date2 = new Date();
        String format = sdf.format(date2);
        Date date1 = sdf.parse(format);
        long time3 = date1.getTime();
        System.out.println("time1:"+time1);
        System.out.println("time3:"+time3);
        if(time1 == time3){
            System.out.println("true");
        };

        System.out.println(parse);



        System.out.println(l);
        long time = date.getTime();
        long time2 =  time+ 2 * 24 * 60 * 60 * 1000;
        long diff = System.currentTimeMillis() - 20210525090402l;
        long days = diff / (1000 * 60 * 60 * 24);
        long hours = (diff - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
        long minutes = (diff - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);
        long abs = Math.abs(days);
        System.out.println(""+abs);
        System.out.println("" + days + "天" + hours + "小时" + minutes + "分");
    }

}
